/*
 * c7_exercise4.cpp
 *
 *  Created on: Sep 2, 2013
 *      Author: cyper.yin
 */
#include <iostream>
using namespace std;

long double probability_field_number(unsigned range, unsigned picks);

long double probability_mega_number(unsigned range);
int main_c7e4(int argc, char **argv) {

	unsigned fieldRange, picks, megaRange;

	cout << "Enter fields number range and field number picks:";
	cin >> fieldRange >> picks;

	cout << "Enter mega number range:";

	cin >> megaRange;

	long double possibilities = probability_field_number(fieldRange, picks)
			* probability_mega_number(megaRange);

	cout << "You have one change in " << possibilities << " of winning."
			<< endl;

	return 0;
}

long double probability_field_number(unsigned range, unsigned picks) {
	long double result = 1.0;
	long double n;
	unsigned p;

	for (n = range, p = picks; p > 0; n--, p--) {
		result = result * n / p;
	}
	return result;
}

/**
 * mega_number has one pick always.
 */
long double probability_mega_number(unsigned range) {
	return range;
}
